// pages/basics/home/index.js
var util = require('../../../utils/util.js')
var wxRequest = require('../../../utils/wxRequest.js')
var app = getApp();
Component({
  /**
   * 页面的初始数据
   */
  data: {
      page:1,
      arr: [],
      classify:['污表情污表情','金馆长','蘑菇头','熊猫人'],
      picList:[],
      triggered: false,
      isPull:true,//true 下拉、false 上拉
      page:0,
      stopLoadMoreTiem:false,

      showModal:false,
      showName:'aa',
      showIngImg:'https://static.ath365.com/Frj0tYNZdiEK4ZgJQsVocDsnZgDn'
  },
  
  //组件的生命周期
  lifetimes: {
    created: function () {
      // 在组件实例刚刚被创建时执行
      var that = this;  
    },
    attached: function() {
      // 在组件实例进入页面节点树时执行
      this.groupList();
      this.getBiaoQing();
    },
    detached: function() {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  methods:{
    gosearch:function(){
      wx.navigateTo({
        url: '/pages/basics/search/search',
      })
    },
    onPulling(e) {
      console.log('onPulling:', e)
    },

    onRefresh() {
      if (this._freshing) return
      this._freshing = true

      this.setData({isPull:true});
      this.setData({page:1});
      this.getBiaoQing();
      
    },

    onRestore(e) {
      console.log('onRestore:', e)
    },

    onAbort(e) {
      console.log('onAbort', e)
    },
    groupList:function(){
      var that = this;
      var data = {};
      var res = util.groupList(data);
      res.then(function(json){
            that.setData({
              classify:JSON.parse(json.data.result),
            });

            console.log(json.data.result);
      });
    },
    showGroup:function (e) {
      var id = e.currentTarget.id,
      url = '/pages/basics/list/list?id=' + id;
      wx.navigateTo({
        url: url
      })
    },
    //上拉
    lower:function(){
      var that = this;
      that.setData({isPull:false});
      console.log("lower");
      if (that.stopLoadMoreTiem) {
        return;
      }
      this.setData({
        page: this.data.page + 1 //上拉到底时将page+1后再调取列表接口
      });
      this.getBiaoQing();
    },
    getBiaoQing:function(){
      var that = this;
      var data = {
        page : that.data.page
      }
      var res = util.getList(data);
      res.then(function(json){
        if(that.data.isPull){
          that.setData({picList:JSON.parse(json.data.result)});
          that.setData({
            triggered: false,
          })
          that._freshing = false;
          console.log(JSON.stringify(json.data.result));
          console.log(that.data.picList[0]);
        }else{
            that.setData({
              picList:that.data.picList.concat(JSON.parse(json.data.result)),
            });
            that.stopLoadMoreTiem = false;
        }
      });
    },
    preventHide:function(e){
      this.setData({showModal:false});
    },
    showTip:function (e) {
      var id = e.currentTarget.id,
      title = e.currentTarget.dataset.name,
      img = e.currentTarget.dataset.path;

      this.setData({
        showIngImg:img,
        showName:title,
        showModal:true
      });
    },
    // 禁止屏幕滚动
    preventTouchMove:function () {
    }
  }
})